package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Rolemaster;
import com.restaurant.service.RolemasterService;

public class RolemasterServiceImpl implements RolemasterService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Rolemaster addOrModify( Rolemaster objRolemaster ) {
       return ( Rolemaster ) hibernateTemplate.merge( objRolemaster );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Rolemaster deleteRecord( Rolemaster objRolemaster ) {
       hibernateTemplate.delete( objRolemaster );
       return objRolemaster;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Rolemaster modifyRecord( Rolemaster objRolemaster ) {
       return ( Rolemaster ) hibernateTemplate.merge( objRolemaster );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Rolemaster> loadAll() {
       return (List<Rolemaster>)hibernateTemplate.findByNamedQuery( "Rolemaster.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Rolemaster loadByPrimaryKey( Long primaryKey ) {
       return (Rolemaster) hibernateTemplate.get( Rolemaster.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Rolemaster deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Rolemaster> loadByHql(String query) {
       return ( List<Rolemaster> ) hibernateTemplate.find( query );
   }
}